(Gray out or enable character commands based on various criteria, such as: whether
 current equipment supports them, whether the character is inflicted with Imp or
 Mute, and whether they've accumulated enough Magic Points to Morph.
 This function also enables Offering to change the aiming of Fight and Capture.)

C2/527D: DA           PHX
C2/527E: 08           PHP
C2/527F: C2 30        REP #$30       (Set 16-bit A, X and Y)
C2/5281: 9B           TXY
C2/5282: BF 4A 54 C2  LDA $C2544A,X  (Get address of character's menu)
C2/5286: AA           TAX 
C2/5287: E2 20        SEP #$20       (Set 8-bit Accumulator)
C2/5289: B9 18 30     LDA $3018,Y
C2/528C: 0C 58 3A     TSB $3A58
C2/528F: B9 E4 3E     LDA $3EE4,Y
C2/5292: 29 20        AND #$20
C2/5294: 85 EF        STA $EF        (if Imp status possessed, turn on Bit 5 of $EF.
                                      if not, the variable is set to 0.)
C2/5296: B9 A4 3B     LDA $3BA4,Y    (weapon properties, right hand)
C2/5299: 19 A5 3B     ORA $3BA5,Y    (merge with weapon properties, left hand)
C2/529C: 49 FF        EOR #$FF       (invert)
C2/529E: 29 82        AND #$82
C2/52A0: 04 EF        TSB $EF        (if neither hand supports Runic, set Bit 7.
                                      if neither hand supports SwdTech, set Bit 1.)
C2/52A2: A9 04        LDA #$04
C2/52A4: 85 EE        STA $EE        (counter variable.. we're going to check
                                      4 menu slots in all)
C2/52A6: DA           PHX            (push address of character's current menu slot)
C2/52A7: 38           SEC            (mark menu slot to be disabled)
C2/52A8: 7B           TDC            (clear 16-bit A)
C2/52A9: BD 00 00     LDA $0000,X    (get command # in current menu slot)
C2/52AC: 30 2D        BMI $52DB      (branch if slot empty)
C2/52AE: 48           PHA            (push command #)
C2/52AF: 18           CLC            (mark menu slot to be enabled)
C2/52B0: A5 EF        LDA $EF
C2/52B2: 89 20        BIT #$20       (are they an Imp?)
C2/52B4: F0 0D        BEQ $52C3      (branch if not)
C2/52B6: A3 01        LDA $01,S    
C2/52B8: 0A           ASL            (command # * 2)
C2/52B9: AA           TAX  
C2/52BA: BF 00 FE CF  LDA $CFFE00,X  (table of command info)
C2/52BE: 89 04        BIT #$04       (is command supported while Imped?)
C2/52C0: D0 01        BNE $52C3      (branch if so)
C2/52C2: 38           SEC            (mark menu slot to be disabled)
C2/52C3: 68           PLA            (fetch command #)
C2/52C4: B0 15        BCS $52DB      (if menu slot is disabled at this point,
                                      don't bother with our next checks)

(This next loop sees if our current command is one that needs special code to assess
 its menu availability -- graying it if unavailable -- or another property, such as
 its aiming.  If so, a special function is called for the command.)

C2/52C6: A2 07 00     LDX #$0007
C2/52C9: DF E9 52 C2  CMP $C252E9,X  (does our current command match one whose menu
                                      availability or aiming can vary?)
C2/52CD: D0 08        BNE $52D7      (if not, compare it to next command in table)
C2/52CF: 8A           TXA 
C2/52D0: 0A           ASL 
C2/52D1: AA           TAX 
C2/52D2: FC F1 52     JSR ($52F1,X)  (call special function for command)
C2/52D5: 80 04        BRA $52DB      (we've gotten a match, so there's no need to
                                      compare our current command against rest of list)
C2/52D7: CA           DEX 
C2/52D8: 10 EF        BPL $52C9      (there are 8 possible commands that need
                                      special checks)
C2/52DA: 18           CLC            (if there was no match, default to enabling the
                                      menu slot)
C2/52DB: FA           PLX 
C2/52DC: 7E 01 00     ROR $0001,X    (2nd byte of current menu slot will have Bit 7 set
                                      if the slot should be grayed out and unavailable.
                                      iow, Carry = 1 -> grayed.  Carry = 0 -> enabled.)

C2/52DF: E8           INX 
C2/52E0: E8           INX 
C2/52E1: E8           INX            (point to next slot in character's menu)
C2/52E2: C6 EE        DEC $EE
C2/52E4: D0 C0        BNE $52A6      (repeat process for all 4 menu slots)
C2/52E6: 28           PLP 
C2/52E7: FA           PLX 
C2/52E8: 60           RTS 


(Data - commands that can potentially get grayed out on the menu in battle,
 or have a property like their aiming altered.)

C2/52E9: 03    (Morph)
C2/52EA: 0B    (Runic)
C2/52EB: 07    (SwdTech)
C2/52EC: 0C    (Lore)
C2/52ED: 17    (X-Magic)
C2/52EE: 02    (Magic)
C2/52EF: 06    (Capture)
C2/52F0: 00    (Fight)


(Data - addresses of functions to check whether above command should be
 enabled, disabled, or otherwise modified on battle menu)

C2/52F1: 26 53   (Morph)
C2/52F3: 22 53   (Runic)
C2/52F5: 1D 53   (SwdTech)
C2/52F7: 14 53   (Lore)
C2/52F9: 14 53   (X-Magic)
C2/52FB: 14 53   (Magic)
C2/52FD: 01 53   (Capture)
C2/52FF: 01 53   (Fight)


(For Capture and Fight menu slots)

C2/5301: B9 58 3C     LDA $3C58,Y (Check for offering)
C2/5304: 4A           LSR 
C2/5305: 90 0C        BCC $5313   (Exit if no Offering)
C2/5307: C2 21        REP #$21    (Set 16-bit Accumulator.  Clear Carry to enable
                                   menu slot.)
C2/5309: A3 03        LDA $03,S   
C2/530B: AA           TAX         (get address of character's current menu slot)
C2/530C: E2 20        SEP #$20    (Set 8-bit Accumulator)
C2/530E: A9 4E        LDA #$4E
C2/5310: 9D 02 00     STA $0002,X (update aiming byte: Cursor start on enemy,
                                   Auto select one party, Auto select both parties
                                   [in this case, that means you'll target both enemy
                                    clumps in a Pincer], and One side only.)
C2/5313: 60           RTS 


(For Lore, X-Magic, and Magic menu slots)

C2/5314: B9 E5 3E     LDA $3EE5,Y
C2/5317: 89 08        BIT #$08     (is character Muted?)
C2/5319: F0 01        BEQ $531C    (branch if not)
C2/531B: 38           SEC          (if they are, mark menu slot to be disabled?)
C2/531C: 60           RTS 


(For SwdTech menu slot)

C2/531D: A5 EF        LDA $EF
C2/531F: 4A           LSR 
C2/5320: 4A           LSR          (Carry = Bit 1, which was set in function C2/527D)
C2/5321: 60           RTS          (if it was set, menu slot will be disabled..
                                    if it wasn't, slot is enabled)


(For Runic menu slot)

C2/5322: A5 EF        LDA $EF
C2/5324: 0A           ASL          (Carry = Bit 7, which was set in function C2/527D)
C2/5325: 60           RTS          (if it was set, menu slot will be disabled..
                                    if it wasn't, slot is enabled)

(For Morph menu slot)

C2/5326: A9 0F        LDA #$0F
C2/5328: CD F6 1C     CMP $1CF6    (compare to Morph supply)
C2/532B: 60           RTS          (if Morph supply isn't at least 16, menu slot will
                                    be disabled..  if it's >=16, slot is enabled)


(Change character commands when wearing MagiTek armor or visiting Fanatics' Tower.
 Change commands based on relics, such as Fight becoming Jump, or Steal becoming Capture.
 Blank or retain certain commands, depending on whether they should be available -- e.g.
   no known dances means no Dance command.)
 Zero character MP if they have no Lore command, no Magic/X-Magic with at least one spell
   learned, and no Magic/X-Magic with an Esper equipped.)

C2/532C: DA           PHX
C2/532D: 08           PHP 
C2/532E: C2 30        REP #$30       (Set 16-bit A, X, and Y)
C2/5330: BC 10 30     LDY $3010,X    (get offset to character info block)
C2/5333: BF 4A 54 C2  LDA $C2544A,X  (get address of character's menu)
C2/5337: 8F 81 21 00  STA $002181    (this means that future writes to $00218n in this function
                                      will modify that character's menu?)
C2/533B: B9 16 16     LDA $1616,Y   (1st and 2nd menu slots)
C2/533E: 85 FC        STA $FC
C2/5340: B9 18 16     LDA $1618,Y   (3rd and 4th menu slots)
C2/5343: 85 FE        STA $FE
C2/5345: B9 14 16     LDA $1614,Y   (out of battle Status Bytes 1 and 2; correspond
                                     to in-battle Status Bytes 1 and 4)
C2/5348: E2 30        SEP #$30      (Set 8-bit A, X, and Y)
C2/534A: 89 08        BIT #$08      (does character have MagiTek?)
C2/534C: D0 06        BNE $5354     (branch if so)
C2/534E: AD BB 3E     LDA $3EBB     (Fanatics' Tower?  must verify this.)
C2/5351: 4A           LSR 
C2/5352: 90 49        BCC $539D     (branch if neither MagiTek nor Fanatics' Tower)
C2/5354: BD D8 3E     LDA $3ED8,X   (get character index)
C2/5357: EB           XBA 
C2/5358: A2 03        LDX #$03      (point to 4th menu slot)
C2/535A: B5 FC        LDA $FC,X     (get command in menu slot)
C2/535C: C9 01        CMP #$01
C2/535E: F0 3A        BEQ $539A     (if Item, skip to next slot)
C2/5360: C9 12        CMP #$12
C2/5362: F0 36        BEQ $539A     (if Mimic, skip to next slot)
C2/5364: EB           XBA           (retrieve character index)
C2/5365: C9 0B        CMP #$0B
C2/5367: D0 08        BNE $5371     (branch if not Gau)
C2/5369: EB           XBA           (get command again)
C2/536A: C9 10        CMP #$10
C2/536C: D0 02        BNE $5370     (branch if not Rage)
C2/536E: A9 00        LDA #$00      (load Fight command into A so that Gau's Rage will get replaced
                                     by MagiTek too.  why not just replace "BNE $5370 / LDA #$00"
                                     with "BEQ formerly_$5376" ??  you got me..)
C2/5370: EB           XBA 
C2/5371: EB           XBA           (once more, command is in bottom of A, character index in top)
C2/5372: C9 00        CMP #$00      (Fight?)
C2/5374: D0 04        BNE $537A     (branch if not.  if it is Fight, we'll replace it with MagiTek)
C2/5376: A9 1D        LDA #$1D       
C2/5378: 80 06        BRA $5380     (go store MagiTek command in menu slot)
C2/537A: C9 02        CMP #$02
C2/537C: F0 02        BEQ $5380     (if Magic, branch..  which just keeps Magic as command?
                                     rewriting it seems inefficient, unless i'm missing
                                     something.)
             
C2/537E: A9 FF        LDA #$FF      (empty command)
C2/5380: 95 FC        STA $FC,X     (update this menu slot)
C2/5382: AD BB 3E     LDA $3EBB     (Fanatics' Tower?  must verify this.)
C2/5385: 4A           LSR 
C2/5386: 90 12        BCC $539A     (branch if not in the tower)
C2/5388: B5 FC        LDA $FC,X     (get menu slot again)
C2/538A: C9 02        CMP #$02
C2/538C: F0 08        BEQ $5396     (branch if Magic command, emptying slot.)
C2/538E: C9 1D        CMP #$1D      (MagiTek?  actually, this is former Fight or Gau+Rage.)
C2/5390: D0 06        BNE $5398     (branch if not)
C2/5392: A9 02        LDA #$02      
C2/5394: 80 02        BRA $5398     (save Magic as command)
C2/5396: A9 FF        LDA #$FF      (empty command)
C2/5398: 95 FC        STA $FC,X     (update menu slot)
C2/539A: CA           DEX 
C2/539B: 10 BD        BPL $535A     (loop for all 4 slots)

C2/539D: 7B           TDC           (clear 16-bit A)
C2/539E: 85 F8        STA $F8
C2/53A0: 8F 83 21 00  STA $002183
C2/53A4: A8           TAY           (Y = 0)

C2/53A5: B9 FC 00     LDA $00FC,Y   (get command from menu slot)
C2/53A8: A2 04        LDX #$04
C2/53AA: 48           PHA 
C2/53AB: A9 04        LDA #$04
C2/53AD: 85 EE        STA $EE        (start checking Bit 2 of variable $11D6)
C2/53AF: BF 52 54 C2  LDA $C25452,X  (commands that can be changed FROM)
C2/53B3: C3 01        CMP $01,S      (is current command one of those commands?)
C2/53B5: D0 0D        BNE $53C4      (branch if not)
C2/53B7: AD D6 11     LDA $11D6     (check Battle Effects 1 byte.
                                     Bit 2 = Fight -> Jump, Bit 3 = Magic -> X-Magic,
                                     Bit 4 = Sketch -> Control, Bit 5 = Slot -> GP Rain,
                                     Bit 6 = Steal -> Capture)
                 
C2/53BA: 24 EE        BIT $EE
C2/53BC: F0 06        BEQ $53C4
C2/53BE: BF 57 54 C2  LDA $C25457,X   (commands to change TO)
C2/53C2: 83 01        STA $01,S       (replace command on stack)
C2/53C4: 06 EE        ASL $EE         (will check the next highest bit of $11D6
                                       in our next iteration)
C2/53C6: CA           DEX 
C2/53C7: 10 E6        BPL $53AF       (loop for all 5 possible commands that can be
                                       converted)

(This next loop sees if our current command is one that needs special code to assess
 its menu availability -- blanking it if unavailable -- or do some other tests.  If so,
 a special function is called for the command.)

C2/53C9: A3 01        LDA $01,S       (get current command)
C2/53CB: A2 05        LDX #$05
C2/53CD: DF 68 54 C2  CMP $C25468,X   (is it one of the commands that can be blanked from menu
                                       or have other miscellaneous crap done?)
C2/53D1: D0 08        BNE $53DB       (branch if not)
C2/53D3: 8A           TXA 
C2/53D4: 0A           ASL 
C2/53D5: AA           TAX             (X = X * 2)
C2/53D6: FC 5C 54     JSR ($545C,X)   (call special function for command)
C2/53D9: 80 03        BRA $53DE       (we've gotten a match, so there's no need to
                                       compare our current command against rest of list)
C2/53DB: CA           DEX 
C2/53DC: 10 EF        BPL $53CD       (there are 6 possible commands that need
                                       special checks)
C2/53DE: 68           PLA             (restore command #, which may've been nulled by our
                                       C2/545C special function)
C2/53DF: 8F 80 21 00  STA $002180     (save command # in first menu byte)
C2/53E3: 8F 80 21 00  STA $002180     (save command # again in second menu byte..  all i know
                                       about this byte is that the top bit will be set if the
                                       menu option is unavailable [blank or gray] )
C2/53E7: 0A           ASL 
C2/53E8: AA           TAX             (X = command * 2, will let us index a command table)
C2/53E9: 7B           TDC             (clear 16-bit A)
C2/53EA: B0 04        BCS $53F0       (branch if command # was negative.  this will put
                                       zero into the menu aiming)
C2/53EC: BF 01 FE CF  LDA $CFFE01,X   (get command's aiming)
C2/53F0: 8F 80 21 00  STA $002180     (store it in a third menu byte)
C2/53F4: C8           INY 
C2/53F5: C0 04        CPY #$04      (loop for all 4 menu slots)
C2/53F7: D0 AC        BNE $53A5
C2/53F9: 46 F8        LSR $F8       (Carry gets set if character has Magic/X-Magic command
                                     and at least one spell known, Magic/X-Magic and an
                                     Esper equipped, or if they simply have Lore.)
C2/53FB: B0 0B        BCS $5408
C2/53FD: A3 02        LDA $02,S     (retrieve the X value originally passed to the function.
                                     iow, the index of the party member whose menu is being
                                     examined)
C2/53FF: AA           TAX 
C2/5400: C2 20        REP #$20      (Set 16-bit A)
C2/5402: 9E 08 3C     STZ $3C08,X   (zero MP)
C2/5405: 9E 30 3C     STZ $3C30,X   (zero max MP)
C2/5408: 28           PLP 
C2/5409: FA           PLX 
C2/540A: 60           RTS 


(Morph menu entry)

C2/540B: A9 04        LDA #$04
C2/540D: 2C BC 3E     BIT $3EBC    (? is Morph available?)
C2/5410: F0 22        BEQ $5434    (if not, go null out command)
C2/5412: 2C BB 3E     BIT $3EBB    (set only for Phunbaba battle #4 [i.e. Terra's second
                                    Phunbaba encounter])
C2/5415: F0 21        BEQ $5438    (if not Phunbaba, just keep command enabled)
C2/5417: A3 05        LDA $05,S    (get the X value originally passed to function C2/532C.
                                    iow, the index of the party member whose menu is being
                                    examined)
C2/5419: AA           TAX 
C2/541A: BD E9 3D     LDA $3DE9,X
C2/541D: 09 08        ORA #$08
C2/541F: 9D E9 3D     STA $3DE9,X  (Cause attack to set Morph)
C2/5422: A9 FF        LDA #$FF
C2/5424: 8D F6 1C     STA $1CF6    (set Morph supply to maximum)
C2/5427: 80 0B        BRA $5434    (by nulling Morph command in menu, we'll stop Terra from
                                    Morphing again and from Reverting?)


(Magic and X-Magic menu entry)

(Blank out Magic/X-Magic menu if no spells are known and no Esper is equipped)

C2/5429: A5 F6        LDA $F6      (# of spells learnt?)
C2/542B: D0 18        BNE $5445    (if some are, branch and set a flag)
C2/542D: A5 F7        LDA $F7      (index of Esper equipped.  this value starts with 0
                                    for Ramuh, and the order matches the Espers' order in
                                    the spell list.  FFh means nothing's equipped)
C2/542F: 1A           INC 
C2/5430: D0 13        BNE $5445    (branch if an Esper equipped)
C2/5432: D0 04        BNE $5438    (Dance and Leap jump here.  obviously, this branch
                                    is never taken if we called this function for Magic
                                    or X-Magic.)
C2/5434: A9 FF        LDA #$FF
C2/5436: 83 03        STA $03,S    (replace current command with empty)
C2/5438: 60           RTS 


(Dance menu entry)

C2/5439: AD 4C 1D     LDA $1D4C  (bitfield of known Dances)
C2/543C: 80 F4        BRA $5432  (if none are, menu entry will be nulled after branch)


(Leap menu entry)

C2/543E: AD E4 11     LDA $11E4
C2/5441: 89 02        BIT #$02   (is Leap available?)
C2/5443: 80 ED        BRA $5432  (if it's not, menu entry will be nulled after branch)


(Lore menu entry)

C2/5445: A9 01        LDA #$01
C2/5447: 04 F8        TSB $F8    (this will stop character's Current MP and Max HP from
                                  getting zeroed in calling function.  Lore always does
                                  this, whereas Magic and X-Magic have conditions..
                                  Also note that Lore never checks whether the menu command
                                  should be available, as Strago knows 3 Lores at startup)
C2/5449: 60           RTS 

(Pointers - functions to remove commands from in-battle menu, or to make
 miscellaneous adjustments)

C2/545C: 0B 54   (Morph)
C2/545E: 3E 54   (Leap)
C2/5460: 39 54   (Dance)
C2/5462: 29 54   (Magic)
C2/5464: 29 54   (X-Magic)
C2/5466: 45 54   (Lore)


(Data - commands that can be removed from menu in some circumstances, or otherwise
 need special functions.)

C2/5468: 03   (Morph)
C2/5469: 11   (Leap)
C2/546A: 13   (Dance)
C2/546B: 02   (Magic)
C2/546C: 17   (X-Magic)
C2/546D: 0C   (Lore)